package org.seven;

import java.io.*;
import java.net.*;
import java.util.List;

/**
 * Created by Administrator on 2016/3/14 0014.
 */
public class ServerThread implements Runnable{
    private Socket client;

    public ServerThread( Socket client ) {
        this.client = client;
    }

    @Override
    public void run() {
        try(
                ObjectOutputStream oos =
                        new ObjectOutputStream( client.getOutputStream() );
                ObjectInputStream ois =
                        new ObjectInputStream( client.getInputStream());
        ){
            // 获取客户端发送的用户信息
            Users u = (Users)ois.readObject();
            DataHelper.ul.add(u);       // 添加到集合内

            DataHelper.index++;

            oos.writeObject(DataHelper.ul);

            System.out.println( DataHelper.index + "\t\t" + u.getName() + "\t\t(/" + u.getIp() + ":" + u.getPort() + ")");
        }catch ( IOException e ) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
